package controller

import (
	"GoAdmin/models"
	"github.com/gin-gonic/gin"
	"net/http"
	"strconv"
)

func FieldList(c *gin.Context) {
	var (
		schoolId string
	)
	page, _ := strconv.Atoi(c.DefaultPostForm("page", "1"))
	pageSize, _ := strconv.Atoi(c.DefaultPostForm("pageSize", "15"))
	offset := (page - 1) * pageSize
	if schoolId = c.PostForm("school_id"); schoolId == "" {
		c.JSON(http.StatusOK, gin.H{"code": 201, "msg": "失败", "data": nil})
		return
	}
	field, _ := new(models.Field).GetFieldList(schoolId, pageSize, offset)
	c.JSON(http.StatusOK, gin.H{"code": 200, "msg": "成功", "data": field})
	return
}

func GetClosurePoint(c *gin.Context) {
	var (
		fieldId  string
		schoolId string
		err      error
		list     []*models.ClosurePoint
	)
	if fieldId = c.PostForm("field_id"); fieldId == "" {
		c.JSON(http.StatusOK, gin.H{"code": 201, "msg": "失败1", "data": nil})
		return
	}
	if schoolId = c.PostForm("school_id"); schoolId == "" {
		c.JSON(http.StatusOK, gin.H{"code": 201, "msg": "失败2", "data": nil})
		return
	}
	if list, err = new(models.Field).GetClosurePoint(schoolId, fieldId); err != nil {
		c.JSON(http.StatusOK, gin.H{"code": 201, "msg": "失败3", "data": nil})
		return
	} else {
		//utils.Resp(c, http.StatusOK, "获取成功", map[string]interface{}{"list": list})
		c.JSON(http.StatusOK, gin.H{"code": 200, "msg": "获取成功", "data": list})
		return
	}
}
